package com.xiebishe.mylibrary.common.groupAdapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RecyclerOneViewAdapter extends RecyclerAdapter<RecyclerOneViewAdapter.OneViewHolder> {

    private final View view;
    private static int staticItemType = -0x8000;
    private int itemType;

    public RecyclerOneViewAdapter(@NonNull View view) {
        this.view = view;
        itemType = staticItemType++;
        if (staticItemType > 0x7fff) {
            staticItemType = -0x8000;
        }
    }

    public RecyclerOneViewAdapter(RecyclerView recyclerView, @LayoutRes int layoutId) {
        this(LayoutInflater.from(recyclerView.getContext()).inflate(layoutId, recyclerView, false));
    }

    public View getView() {
        return view;
    }

    @NonNull
    @Override
    public OneViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new OneViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull OneViewHolder holder, int position) {
    }

    @Override
    public int getItemCount() {
        return 1;
    }


    @Override
    public int getItemViewType(int position) {
        return itemType;
    }

    public <T extends View> T findViewById(@IdRes int id) {
        return view.findViewById(id);
    }

    static class OneViewHolder extends RecyclerView.ViewHolder {

        OneViewHolder(View itemView) {
            super(itemView);
        }
    }
}
